package com.task.manager.mapper;

import com.task.manager.domain.Actuator;
import com.task.manager.domain.Task;

import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

public class ActuatorSqlProvider {

    public String insertSelective(Actuator record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("t_actuator");
        
        if (record.getId() != null) {
            sql.VALUES("ID", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getActuatorName() != null) {
            sql.VALUES("ACTUATOR_NAME", "#{actuatorName,jdbcType=VARCHAR}");
        }
        
        if (record.getActuatorClass() != null) {
            sql.VALUES("ACTUATOR_CLASS", "#{actuatorClass,jdbcType=VARCHAR}");
        }
        
        if (record.getActuatorType() != null) {
            sql.VALUES("ACTUATOR_TYPE", "#{actuatorType,jdbcType=VARCHAR}");
        }
        
        if (record.getActuatorCode() != null) {
            sql.VALUES("ACTUATOR_CODE", "#{actuatorCode,jdbcType=VARCHAR}");
        }
        
        if (record.getActuatorProtocol() != null) {
            sql.VALUES("ACTUATOR_PROTOCOL", "#{actuatorProtocol,jdbcType=VARCHAR}");
        }
        
        if (record.getActuatorMethod() != null) {
            sql.VALUES("ACTUATOR_METHOD", "#{actuatorMethod,jdbcType=VARCHAR}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(Actuator record) {
        SQL sql = new SQL();
        sql.UPDATE("t_actuator");
        
        if (record.getActuatorName() != null) {
            sql.SET("ACTUATOR_NAME = #{actuatorName,jdbcType=VARCHAR}");
        }
        
        if (record.getActuatorClass() != null) {
            sql.SET("ACTUATOR_CLASS = #{actuatorClass,jdbcType=VARCHAR}");
        }
        
        if (record.getActuatorType() != null) {
            sql.SET("ACTUATOR_TYPE = #{actuatorType,jdbcType=VARCHAR}");
        }
        
        if (record.getActuatorCode() != null) {
            sql.SET("ACTUATOR_CODE = #{actuatorCode,jdbcType=VARCHAR}");
        }
        
        if (record.getActuatorProtocol() != null) {
            sql.SET("ACTUATOR_PROTOCOL = #{actuatorProtocol,jdbcType=VARCHAR}");
        }
        
        if (record.getActuatorMethod() != null) {
            sql.SET("ACTUATOR_METHOD = #{actuatorMethod,jdbcType=VARCHAR}");
        }
        
        sql.WHERE("ID = #{id,jdbcType=INTEGER}");
        
        return sql.toString();
    }
    
    public String queryActuatorByParam(Actuator record) {
    	SQL sql = new SQL();
    	sql.SELECT("t.*");
    	sql.FROM("t_actuator t");
    	if(!StringUtils.isEmpty(record.getActuatorCode())) {
    		sql.WHERE("t.ACTUATOR_CODE like CONCAT('%',#{actuatorCode,jdbcType=VARCHAR},'%') ");
    	}
    	
    	if(!StringUtils.isEmpty(record.getActuatorName())) {
    		sql.WHERE("t.ACTUATOR_NAME like CONCAT('%',#{actuatorName,jdbcType=VARCHAR},'%') ");
    	}
    	sql.ORDER_BY("t.id desc");
    	return sql.toString();
    }
}